<%@ page language="java" import="java.util.*,java.sql.*" pageEncoding="utf-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>My JSP 'index.jsp' starting page</title>
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->
  <style>
        body{
            padding:0;
            margin:0;
            font-size:16px;
            font-family:"microsoft yahei";
        }
        .div1{
            width:100%;
            text-align: center;
        }
        .div2{
            width:30%;
            float:left;
        }
        .div2 button{
            display:block;
            padding:5px 10px;
            background-color: #c40000;
            border:none;
            border-radius: 5px;
            margin:0px 0 20px 45%;
            cursor:pointer;
            width:100px;
        }
        .div2 button a{
            display: block;
            color:white;
            font-size:15px;
            text-decoration: none;
        }
        .div2 button a:hover{
            text-decoration: underline;
        }
        .div3{
            float: left;
            width:65%;
        }
        .div_top{
            width:100%;
            display:flex;
            flex-wrap: wrap;
            flex-direction: row;
        }
        .div_top h1{
            margin-left:50px;
            color:#c40000;
        }
        .div_top input{
            height:30px;
            margin-top:25px;
        }
        #search{
            margin-left:40%;
            width:200px;
            border:2px solid #c40000;
            padding:0 3px;
        }
        #but{
            border:none;
            background-color: #c40000;
            color:white;
            height:34px;
            font-size: 15px;
            width:60px;
            cursor:pointer;
        }
        .div4{
            clear: both;
        }
        .div_bottom{
            width:100%;
            display: flex;
            flex-flow: row wrap;
            justify-items: center;
        }
        .div_bottom table{
            width:100%;

        }
        .div_bottom table,th,tr,td{
            border:1px solid #c40000;
        }
    </style>
</head>
<body>
<%
try{
Class.forName("com.mysql.jdbc.Driver");
String url = "jdbc:mysql://localhost:3306/homework?useUnicode=true&amp;characterEncoding=utf-8";
Connection conn=DriverManager.getConnection(url,"root","root123");

String sql = "select * from stuinfo";

PreparedStatement ps = conn.prepareStatement(sql);
ResultSet rs = ps.executeQuery();

%>
    <div class="div1">
        <div class="div2">
            <button style="margin-top:30px;"><a href="#">初级</a></button>
            <button><a href="#">中级</a></button>
            <button><a href="#">高级</a></button>
            <a href="zhuce.html" style="text-decoration: none;"><button >注册</button></a>
            <button><a href="#">退出系统</a></button>
        </div>
        <div class="div3">
            <div class="div_top">
                <h1>考试系统</h1>
                <input id="search" type="text" placeholder="请输入要搜索的关键字">
                <input id="but" type="button" value="搜索"/>
            </div>
            <div class="div_bottom">
                <table border="1">
                    <tr>
                        <th></th>
                        <th>名字</th>
                        <th>项目</th>
                        <th>成绩</th>
                        <th>总分</th>
                    </tr>
                    <%
                    while(rs.next()){
                    %>
                    <tr>
                        <th>
                        <% 
                        out.print(rs.getString(1));
                        %>
                        </th>
                        <td>
                        <%
                        out.print(rs.getString(2));
                        %>
                        </td>
                        <td>
                        <%
                        out.print(rs.getString(3));
                        %>
                        </td>
                        <td>
                        <% 
                         out.print(rs.getString(4));
                        %>
                        </td>
                       
                    </tr>
      			<%
                    };

      			%>
                </table>
            </div>
        </div>
        <div class="div4"></div>
    </div>
    <%
    rs.close();
    ps.close();
    conn.close();
}catch(Exception e){
	e.printStackTrace();
}
    %>
</body>
</html>
